// 动作分配兼数据初始化
import {
    FETCH_COLOR_REQUEST, FETCH_COLOR_SUCCESS,
    ADD_COLOR_REQUEST, SAVE_COLOR_FAILURE, SAVE_COLOR_SUCCESS
} from "./redux-action";

const initialContentState = {
    data: {
        "total": 1,
        "list": [
            {
                "id": 2,
                "name": "文字不红了",
                "order": 1
            }
        ]
    },
    isLoading: false,
}

export function contentReducer(state = initialContentState, action) {
    switch (action.type) {
        case ADD_COLOR_REQUEST: {
            return Object.assign({}, state, {
                saveStatus: 'SAVING'
            });
        }
        case SAVE_COLOR_FAILURE: {
            return Object.assign({}, state, {
                saveStatus: 'ERROR'
            });
        }
        case SAVE_COLOR_SUCCESS: {
            return Object.assign({}, state, {
                data: action.color_data,
                person: {
                    name: '',
                    email: '',
                    course: null,
                    department: null
                },
                saveStatus: 'SUCCESS'
            });
        }
        case FETCH_COLOR_REQUEST: {
            return Object.assign({}, state, {
                isLoading: true
            })
        }
        case FETCH_COLOR_SUCCESS: {
            return Object.assign({}, state, {
                data: action.color_data,
                isLoading: false
            });
        }
        default: {
            return state;
        }
    }
}